package query

import (
	"context"

	v1 "code.byted.org/bytertc/whiteboard_server/biz/api/pb/v1"
	"code.byted.org/bytertc/whiteboard_server/biz/service/command"
	"code.byted.org/bytertc/whiteboard_server/biz/service/command/base"
)

func NewActionCountCommand(ctx context.Context, cmd *base.Command, boardId int32, pageId string) *actionCountCommand {
	return &actionCountCommand{
		Command: *cmd,
		boardId: boardId,
		pageId:  pageId,
	}
}

type actionCountCommand struct {
	base.Command
	boardId int32
	pageId  string
}

func (a *actionCountCommand) GetBoardId() int32 {
	return a.boardId
}

func (a *actionCountCommand) GetPageId() string {
	return a.pageId
}

func (a *actionCountCommand) Execute(ctx context.Context) []command.Result {
	countMap, err := a.Repo.GetActionCount(ctx, a)
	resp := &v1.GetActionCountResponse{
		BoardId:     a.boardId,
		PageId:      a.pageId,
		ActionCount: countMap,
	}
	result := &base.Result{
		Msg:         resp,
		IsBroadcast: false,
		CommandType: v1.Command_kGetActionCount,
		Error:       err,
	}
	return []command.Result{result}
}
